/** 
 * All Rights Reserved , Copyright (C) 2020 , 青岛鼎信通讯股份有限公司
 * 
 *MeetTaskMasterController
 * 任务信息主表
 * 
 * 修改纪录
 * 2020-08-31 版本：1.0 shenyouyi 创建。
 * @version 版本：1.0
 * @author 作者：shenyouyi
 * 创建日期：2020-08-31
 */

package com.topscomm.meet.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topscomm.meet.controller.auto.MeetTaskMasterControllerAuto;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: shenyouyi
 * @date: 2020-08-31
 * @description:任务信息主表Controller
 * @modify:
 */
@RestController
@RequestMapping("meet/taskMaster")
public class MeetTaskMasterController extends MeetTaskMasterControllerAuto implements IMeetTaskMasterController {

	@Value("${meetTask.maxBatchSize}")
	private Integer taskMaxBatchSize;

	/**
	 * @author: shenyouyi
	 * @date: 2020-08-31
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_meetID")) {
			String value = paraMap.get("qry_meetID").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and meetid = {0} ", value);
		}
		if (paraMap.containsKey("qry_title")) {
			String value = paraMap.get("qry_title").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and taskmaintitle like '%{0}%' ", value);
		}
		return sql.toString();
	}

	/**
	 * @author: shenyouyi
	 * @date: 2020-08-31
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	/**
	 * @author: shenyouyi
	 * @date: 2020-08-31
	 * @param: paraMap
	 * @return
	 * @description: 查询选择的角色、部门、团队、人员是否能查询出人员
	 * @modify:
	 */
	@GetMapping(value = "/confirmChooseUsers")
	public ResponseResult<Object> confirmChooseUsers(@RequestParam(required = false) Map<String, Object> paraMap) {
		/*
		 * boolean isHaveUser = this.service.searchHaveUserByCondition(paraMap);
		 * Map<String, Object> resultMap = new HashMap<>();
		 * resultMap.put("isHaveUser", isHaveUser);
		 */
		int userCount = this.service.searchCountUserByCondition(paraMap);
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("isHaveUser", userCount > 0);
		resultMap.put("isLegalCount", userCount < taskMaxBatchSize);
		resultMap.put("taskMaxBatchSize", taskMaxBatchSize);
		return ResponseResult.ok(resultMap);
	}
}
